package main

import (
	"TestGo/Time/function"
	"fmt"
	"time"
)

func main() {
	//获取当前时间
	fmt.Println(time.Now())
	fmt.Printf("年=%v\n", time.Now().Year())
	fmt.Printf("月=%v\n", time.Now().Month())
	fmt.Printf("月=%v\n", int(time.Now().Month()))
	fmt.Printf("日=%v\n", time.Now().Day())
	fmt.Printf("时=%v\n", time.Now().Hour())
	fmt.Printf("分=%v\n", time.Now().Minute())
	fmt.Printf("秒=%v\n", time.Now().Second())
	//格式化日期时间
	fmt.Printf(time.Now().Format("2006/01/02 15:04:05\n"))
	fmt.Printf(time.Now().Format("2006\n"))
	fmt.Printf(time.Now().Format("01\n"))
	fmt.Printf(time.Now().Format("02\n"))
	fmt.Printf(time.Now().Format("15:04:05\n"))

	//每隔一秒钟
	i := 0
	for {
		fmt.Printf(time.Now().Format("2006/01/02 15:04:05\n"))
		//休眠
		time.Sleep(time.Second)
		i++
		if i >= 10 {
			break
		}
	}
	//Unix/UnixNano获取随机数字
	fmt.Printf("unix时间戳=%v unixnano时间长=%v", time.Now().Unix(), time.Now().UnixNano())
	start := time.Now().Unix()
	str := function.Test()
	end := time.Now().Unix()
	fmt.Printf("执行完的字符串=%v\n 花费的时间=%vs", str, end-start)

}
